package com.sitanyun.merchant.guide.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sitanyun.merchant.guide.R;
import com.sitanyun.merchant.guide.bean.BankBean;
import com.sitanyun.merchant.guide.weiht.StringReplaceUtil;

import java.util.List;

/**
 * Created by jzl
 * on 2022/1/14.
 * 提现适配器
 */
public class LvBankDialogAdapter extends BaseAdapter {
   private Context context;
   private List<BankBean.DataBean> banklist;
   private  String banks;
  private int positions =-1;
    public LvBankDialogAdapter(Context context, List<BankBean.DataBean> banklist,String banks) {
        this.context = context;
        this.banklist = banklist;
        this.banks = banks ;
    }
    /*
     * 用于设置当前位置
     */
    public  void setPosition(int position) {
        this.positions = position;
    }
    @Override
    public int getCount() {
        return banklist.size();
    }

    @Override
    public Object getItem(int position) {
        return banklist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
         convertView = LayoutInflater.from(context).inflate(R.layout.lvbank_item, null);
        ImageView idselect = convertView.findViewById(R.id.id_select);
        TextView   lvbankname = convertView.findViewById(R.id.lv_bankname);
        if (banklist.get(position).getBankName().isEmpty()){
            lvbankname.setText("银行卡"+"("+ StringReplaceUtil.bankCardReplaceWithStar(banklist.get(position).getBankCardNum())+")");

        }else {
            lvbankname.setText(banklist.get(position).getBankName()+"("+ StringReplaceUtil.bankCardReplaceWithStar(banklist.get(position).getBankCardNum())+")");

        }
        if (positions==-1){
            if (banks.equals(lvbankname.getText().toString().trim())){
                Glide.with(context).load(R.mipmap.cbxz).into(idselect);
             //   idselect.setChecked(true);
            }else {
                Glide.with(context).load(R.mipmap.cbwx).into(idselect);
             //   idselect.setChecked(false);
            }
        }else {
            //       //选择
            if (positions == position) {
             //   idselect.setChecked(true);
                Glide.with(context).load(R.mipmap.cbxz).into(idselect);
            } else {
             //   idselect.setChecked(false);
                Glide.with(context).load(R.mipmap.cbwx).into(idselect);
            }
        }

          return convertView;
    }

}
